﻿using System.Collections;
using System.Collections.Generic;
using PMS.IRepository;
using PMS.IServices;
using PMS.Models.Base;
using PMS.Repository;
using PMS.Utils;

namespace PMS.Services
{
    public class BaseRoleService : IBaseRoleService
    {
        IBaseRoleRepository _baseRoleRepository = new BaseRoleRepository();

        #region 公共方法

        public int Add(BaseRole user)
        {
            return _baseRoleRepository.Add(user);
        }

        public int Edit(BaseRole user)
        {
            return _baseRoleRepository.Edit(user);
        }

        public BaseRole Dtl(int id)
        {
            return _baseRoleRepository.Dtl(id);
        }

        public bool IsExists(int id)
        {
            return _baseRoleRepository.IsExists(id);
        }

        public int Delete(int id, string deleteBy)
        {
            return _baseRoleRepository.Delete(id, deleteBy);
        }

        public int Delete(int[] ids, string deleteBy)
        {
            return _baseRoleRepository.Delete(ids, deleteBy);
        }

        public List<BaseRole> GetList()
        {
            return _baseRoleRepository.GetList();
        }

        public List<BaseRole> GetList(Hashtable ht, string orderFiled, string sort, int pageIndex, int pageSize, out int counts)
        {
            return _baseRoleRepository.GetList(ht, orderFiled, sort, pageIndex, pageSize, out counts);
        }

        #endregion

        public List<BaseRole> GetList(Hashtable ht)
        {
            string strWhere = string.Empty;
            Dictionary<string, object> param = new Dictionary<string, object>();
            if (ht.IsNullOrEmptyByKey("RoleName"))
            {
                strWhere += " And RoleName like @RoleName ";
                param.Add("@RoleName", ht["RoleName"]);
            }

            if (ht.IsNullOrEmptyByKey("IsDel"))
            {
                strWhere += " And IsDel = @IsDel ";
                param.Add("@IsDel", ht["IsDel"]);
            }
            else
            {
                strWhere += " And IsDel = 0 ";
            }

            string strSql = "Select * from BaseRole where 1=1" + strWhere;

            return _baseRoleRepository.GetList(strSql, param);

        }
    }
}